package com.example.learn.sort;

public class ShellSort {
    public static int[] shellSort(int[] array) {
        int len = array.length;
        int temp,gap = len / 2;
        while (gap > 0) {
            for (int i = gap; i < len; i++) {
                temp = array[i];
                int preIndex = i - gap;
                while (preIndex >= 0 && array[preIndex] > temp) {
                    array[preIndex + gap] = array[preIndex];
                    preIndex -= gap;
                }
                array[preIndex + gap] = temp;
            }
            gap = gap / 2;
        }
        return  array;
    }

    public static void main(String[] args) {
        int[] example = {25,2,68,4,6,5,7,8,32,1};
        System.out.println(shellSort(example));
    }
}
